<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文章详情页</title>
    <link href="/style/bootstrap.min.css" rel="stylesheet" />
    <link href="/style/bootstrap-icons.min.css" rel="stylesheet">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/bootstrap.bundle.min.js"></script>
    <script src="/js/htmx.min.js"></script>
    <script src="/js/handlebars.min.js"></script>
    <script src="/js/client-side-templates.js"></script>
</head>
<body>
    <header class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">首页</a>
            <div id="profile-container" class="d-flex" hx-get="/api/auth/profile" hx-trigger="load"
                hx-ext="client-side-templates" handlebars-template="profile-template" hx-swap="innerHTML"></div>
        </div>
    </header>
    <div class="container mt-4" id="article-detail">

    </div>
<script id="article-detail-template" type="text/x-handlebars-template">
    <div class="article">
        <h1>{{title}}</h1>
        <p><strong>分类</strong>:{{#each categories}}<span>{{name}}</span>{{/each}}</p>
        <p><strong>标签</strong>:{{#each tags}}<span>{{name}}</span>{{/each}}</p>
        <hr/>
        <div class="content">{{{content}}}</div>
    </div>
</script>
<script>
    const articleId = new URLSearchParams(window.location.search).get('id');
    fetch(`/api/articles/${articleId}`)
    .then(res=>res.json())
            .then(data=>{
                const templateSource = document.getElementById('article-detail-template').innerHTML;
                const render = Handlebars.compile(templateSource);
                const html = render(data);
                const articleDetail= document.getElementById('article-detail');
                articleDetail.innerHTML = html;
                htmx.process(articleDetail);
            })
</script>   
</body>
</html>